<?php defined('SYSPATH') or die('No direct script access.');
require ('application/classes/dao/base.php');
class Controller_categorym extends Controller {


	public function action_index(){
		$result = rpcCall("category.categorylist",null);
		echo View::factory('manager/category')->bind("category",$result)->set('type','list');
	}
	public function action_update_page(){

		$parm = get($this->request);
		$result = rpcCall("category.detail",$parm['id']);
		print_r($result);
		echo View::factory('manager/updatecategory')->bind("category",$result);
	}
	public function action_detail(){
		$parm = get($this->request);

		if(!isset($parm['id']) ||($parm['id'])==""){
        	echo "id不能为空";
            exit;
         }

		$result = rpcCall("category.categoryByParent",$parm['id']);
		echo View::factory('manager/detailcategory')->bind("category",$result)->set('type','detail');

	}
	public function action_updateData(){
		$parm = post($this->request);

		rpcCall("category.updateData",$parm);
		self::redirectIndex();
	}
	public function action_update(){
		$parm = get($this->request);

		if(!isset($parm['id']) ||($parm['id'])==""){
        	echo "id不能为空";
            exit;
        }
        if(!isset($parm['id']) ||($parm['status'])==""){
        	echo "id不能为空";
            exit;
        }
		$result = rpcCall("category.updateStatus",$parm);
		self::redirectIndex();

	}
	public function action_category(){
		$parm = get($this->request);
		$result = rpcCall("category.categoryByParent",$parm['parentId']);
		echo json_encode($result);
	}
	public function action_insert(){
		$parm = post($this->request);
		if(!isset($parm['name']) ||($parm['name'])==""){
        	echo "名称不能为空";
            exit;
        }
		if(!isset($parm['sort']) ||($parm['sort'])==""){
        	die ("名称不能为空");
        }
        if(!isset($parm['parentId']) ||($parm['parentId'])==""){
        	die ("分类不能为空");
        }

        $result = rpcCall("category.add",$parm);
		self::redirectIndex();

	}
	public function redirectIndex(){
		echo "<script>window.location.href='".Url::base()."index.php/categorym/index'</script>";
	}

}
